//index.js
//获取应用实例
const app = getApp();

import http from "../../utils/http_promise.js";

Page({

  data: {
    houses:[],
    currentPage:1,
    searching:false,
    isLoadding:false,
    isFinished:false
  },
  
  onLoad: function () {
    this.getData();
  },
  
  onReachBottom(){
     if(this.data.isLoadding || this.data.isFinished){
        return false;
     }
     this.getData();
  },
  
  getData(){
  
    let that = this;
    this.setData({
       isLoadding:true
    })
    http.request({
      url: "/house/list?page="+that.data.currentPage
    })
    .then(res => {
      
      that.setData({
        isLoadding: false
      })
    
      var tmpArr = that.data.houses;
      
      // 判断数据是否加载完成
      if(res.data.data.length==0) {
        this.setData({ 
          isFinished: true 
        });
      }

      tmpArr = tmpArr.concat(res.data.data);

      that.setData({
        houses: tmpArr
      })
      that.data.currentPage++;
    })
    
  },

  onClick(e) {
    this.setData({
      searching: false
    })

  },

  onSearch() {
    this.setData({
      searching: true
    })
  },

  onHide: function () {
   // console.log("page ---onHide---");
  },
  onUnload: function () {
   // console.log("page ---onUnload---");
  }

  

})
